# include <algorithm>
# include <cstdio>
# include <iostream>
# include <cstring>
# include <string>
# define MAXN 50001
using namespace std;

int q[26] = {4, 2, 5, 6, 1, 4, 5, 6, 7, 2, 3, 4, 8, 9, 3, 1, 2, 6, 8, 9, 2, 6, 3, 2, 5, 7}, n, m;

pair<int, string> w[MAXN];

inline int gs(string str) { 
    int s = 0;
    for(int i = 0; i < str.length(); i++) s += q[str[i] - 'a'];
    return s;
}

inline bool cmp(pair<int, string> a, pair<int, string> b) { 
    if(a.first ^ b.first) return a.first > b.first;
    if(a.second.size() ^ b.second.size()) return a.second.size() > b.second.size();
    return a.second > b.second;
}

int main() { 
    freopen("crack.in", "r", stdin);
    freopen("crack.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) { 
        string a;
        cin >> a;
        w[i] = make_pair(gs(a), a);
    }
    sort(w + 1, w + n + 1, cmp);
    for(int i = 1; i <= m; i++) { 
        cout << w[i].second << " " << w[i].first << endl;
    }
}
